import { defineConfig } from "vite";
import requireTransform from "vite-plugin-require-transform";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";

const pathResolve = (dir) => resolve(__dirname, dir);
// https://vitejs.dev/config/
export default defineConfig({
  //i18N警告
  define: {
    __VUE_I18N_FULL_INSTALL__: true,
    __VUE_I18N_LEGACY_API__: true,
    __INTLIFY_PROD_DEVTOOLS__: false,
  },
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
    requireTransform({
      fileRegex: /.js$|.vue$/,
    }),
  ],

  resolve: {
    alias: {
      "@": pathResolve("./src"), // 新增
    },
  },

  server: {
    proxy: {
      "/api": {
        target: "https://sea.im/api",
        // target: "http://localhost:7125/api",
        changeOrigin: true, //支持跨域
        rewrite: (path) => path.replace(/^\/api/, ""), //重写路径,替换/api
      },
    },
    // open: true,
  },
});
